package com.southminority.ethnic.service.email;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailServiceImpl implements EmailService {

    @Autowired
    private JavaMailSender mailSender;
    @Value("${spring.mail.username}")
    private String from;

    @Value("${spring.mail.email-begin-theme:【南方少数民族语言文化资源平台】}")
    private String emailBeginTheme;

    @Override
    public void sendSimpleMail(String to, String subject, String content, String... cc) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(emailBeginTheme + subject);
        message.setText(content);
        if (cc.length > 0) {
            message.setCc(cc);
        }
        mailSender.send(message);
    }
}
